USE [CyberAdmin]
GO

/****** Object:  StoredProcedure [dbo].[spUsers_Ins]    Script Date: 02/12/2013 10:20:16 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spUsers_Ins]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spUsers_Ins]
GO

USE [CyberAdmin]
GO

/****** Object:  StoredProcedure [dbo].[spUsers_Ins]    Script Date: 02/12/2013 10:20:16 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO


CREATE PROCEDURE [dbo].[spUsers_Ins]
	@FIRSTNAME [VARCHAR](50),
	@LASTNAME [VARCHAR](50),
	@USERNAME [VARCHAR](50),
	@USERPASSWORD [VARCHAR](50),
	@KEEPALIVE [DATETIME],
	@IDUSERTYPE [INT],
	@IDSTATUS [INT],
	@IDUSERCREATOR [INT],
	@ISSUPERUSER [BIT],
	@INSERTDATE [DATETIME],
	@MODIFYDATE [DATETIME],
	@EMAIL [VARCHAR](255),
	@CELPHONE [VARCHAR](50),
	@HOMEPHONE [VARCHAR](50),
	@OFFICEPHONE [VARCHAR](50),
	@FAX [VARCHAR](50),
	@ADDRESS [VARCHAR](250),
	@CITY [VARCHAR](250),
	@IDPROVINCE [INT],
	@IDNATION [INT],
	@CAP [VARCHAR](10),
	@PAGINAWEB [VARCHAR](250),
	@NOTE [VARCHAR](MAX),
	@IDCOMPANY [INT],
	@IDBUSINESSUNIT [INT],
	@BIRTHDATE [SMALLDATETIME],
	@USERCODE [VARCHAR](10),
	@IDMODIFYUSER int,
	@EXCEPTIONNAME [VARCHAR](50),
	@EXCEPTIONLASTNAME [VARCHAR](50),
	@Codice_dipendente [varchar] (8),
    @Generazione_ripa00 [varchar] (1),
    @Numero_Rapporto int
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @ULTIMOID INT, @COUNTEDITROW INT

	INSERT INTO USERSHR
	  (
		FIRSTNAME,
		LASTNAME,
		USERNAME,
		USERPASSWORD,
		KEEPALIVE,
		IDUSERTYPE,
		IDSTATUS,
		IDUSERCREATOR,
		ISSUPERUSER,
		INSERTDATE,
		MODIFYDATE,
		EMAIL,
		CELPHONE,
		HOMEPHONE,
		OFFICEPHONE,
		FAX,
		ADDRESS,
		CITY,
		IDPROVINCE,
		IDNATION,
		CAP,
		PAGINAWEB,
		NOTE,
		IDCOMPANY,
		IDBUSINESSUNIT,
		BIRTHDATE,
		USERCODE,
		EXCEPTION_NAME,
		EXCEPTION_LASTNAME,
		CODICE_DIPENDENTE,
		GENERAZIONE_RIPA00,
		NUMERO_RAPPORTO)
	VALUES
	( 
		@FIRSTNAME,
		@LASTNAME,
		@USERNAME,
		@USERPASSWORD,
		@KEEPALIVE,
		@IDUSERTYPE,
		@IDSTATUS,
		@IDUSERCREATOR,
		@ISSUPERUSER,
		@INSERTDATE,
		@MODIFYDATE,
		@EMAIL,
		@CELPHONE,
		@HOMEPHONE,
		@OFFICEPHONE,
		@FAX,
		@ADDRESS,
		@CITY,
		@IDPROVINCE,
		@IDNATION,
		@CAP,
		@PAGINAWEB,
		@NOTE,
		@IDCOMPANY,
		@IDBUSINESSUNIT,
		@BIRTHDATE,
		@USERCODE,
		@EXCEPTIONNAME,
		@EXCEPTIONLASTNAME,
		@Codice_dipendente,
		@Generazione_ripa00,
		@Numero_Rapporto)

	SET @ULTIMOID = (SELECT MAX(IDUser) FROM USERS)

	IF @@ROWCOUNT = 1
	BEGIN
		EXECUTE @COUNTEDITROW = [dbo].[spHistoryUsers_InsByIDUser] @ULTIMOID, @IDMODIFYUSER, 1

		IF @COUNTEDITROW = 1
			RETURN @ULTIMOID
	
	END

	RETURN -1
END

GO


USE [CyberAdmin]
GO

/****** Object:  StoredProcedure [dbo].[spUsers_Upd]    Script Date: 02/12/2013 10:25:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[spUsers_Upd]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[spUsers_Upd]
GO

USE [CyberAdmin]
GO

/****** Object:  StoredProcedure [dbo].[spUsers_Upd]    Script Date: 02/12/2013 10:25:55 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO



CREATE PROCEDURE [dbo].[spUsers_Upd]
	@IDUSER [INT],
	@FIRSTNAME [VARCHAR](50),
	@LASTNAME [VARCHAR](50),
	@USERNAME [VARCHAR](50),
	@USERPASSWORD [VARCHAR](50),
	@KEEPALIVE [DATETIME],
	@IDUSERTYPE [INT],
	@IDSTATUS [INT],
	@IDUSERCREATOR [INT],
	@ISSUPERUSER [BIT],
	@MODIFYDATE [DATETIME],
	@EMAIL [VARCHAR](255),
	@CELPHONE [VARCHAR](50),
	@HOMEPHONE [VARCHAR](50),
	@OFFICEPHONE [VARCHAR](50),
	@FAX [VARCHAR](50),
	@ADDRESS [VARCHAR](250),
	@CITY [VARCHAR](250),
	@IDPROVINCE [INT],
	@IDNATION [INT],
	@CAP [VARCHAR](10),
	@PAGINAWEB [VARCHAR](250),
	@NOTE [VARCHAR](MAX),
	@IDCOMPANY [INT],
	@IDBUSINESSUNIT [INT],
	@BIRTHDATE [SMALLDATETIME],
	@USERCODE [VARCHAR](10),
	@IDMODIFYUSER int,
	@EXCEPTIONNAME [VARCHAR](50),
	@EXCEPTIONLASTNAME [VARCHAR](50),
	@CODICE_DIPENDENTE [VARCHAR] (11),
	@GENERAZIONE_RIPA00[VARCHAR](1)
AS
BEGIN
	SET NOCOUNT ON;
	DECLARE @COUNTEDITROW INT

	UPDATE USERSHR
	SET
		FIRSTNAME = @FIRSTNAME,
		LASTNAME = @LASTNAME,
		USERNAME = @USERNAME,
		USERPASSWORD = @USERPASSWORD,
		KEEPALIVE = @KEEPALIVE,
		IDUSERTYPE = @IDUSERTYPE,
		IDSTATUS = @IDSTATUS,
		IDUSERCREATOR = @IDUSERCREATOR,
		ISSUPERUSER = @ISSUPERUSER,
		MODIFYDATE = @MODIFYDATE,
		EMAIL = @EMAIL,
		CELPHONE = @CELPHONE,
		HOMEPHONE = @HOMEPHONE,
		OFFICEPHONE = @OFFICEPHONE,
		FAX = @FAX,
		ADDRESS = @ADDRESS,
		CITY = @CITY,
		IDPROVINCE = @IDPROVINCE,
		IDNATION = @IDNATION,
		CAP = @CAP,
		PAGINAWEB = @PAGINAWEB,
		NOTE = @NOTE,
		IDCOMPANY = @IDCOMPANY,
		IDBUSINESSUNIT = @IDBUSINESSUNIT,
		BIRTHDATE = @BIRTHDATE,
		USERCODE = @USERCODE,
		EXCEPTION_NAME = @EXCEPTIONNAME,
		EXCEPTION_LASTNAME = @EXCEPTIONLASTNAME,
		codice_dipendente=@CODICE_DIPENDENTE,
		generazione_ripa00=@GENERAZIONE_RIPA00
	WHERE IDUSER = @IDUSER

	IF @@ROWCOUNT = 1
	BEGIN
		EXECUTE @COUNTEDITROW = [dbo].[spHistoryUsers_InsByIDUser] @IDUSER, @IDMODIFYUSER, 3
			
		IF @COUNTEDITROW = 1
			RETURN 1

	END
	
	RETURN -1
END


GO


